package com.example.leepong.Game.Interaction;
import com.example.leepong.Game.Engine;
import com.example.leepong.Game.Shapes.Coordinates;

/**
 * Created by Ichigo on 21/04/2014.
 */
public class TouchDetector {

    private Engine _engine;
    private TouchManager _touchManager;

    public TouchDetector(Engine engine, TouchManager touchManager) {
        _engine = engine;
        _touchManager = touchManager;
    }

    public void NotifyTap(Coordinates tapCoords) {

        boolean handled = false;
        if (_engine.BottomRacket.Rect.Contains(tapCoords)) {
            handled = _touchManager.OnRightRaquetTap(tapCoords);
        }
        if (handled) return;

        if (_engine.TopRacket.Rect.Contains(tapCoords)) {
            handled = _touchManager.OnLeftRaquetTap(tapCoords);
        }
        if (handled) return;

        if (_engine.Land.Rect.Contains(tapCoords)) {
            handled = _touchManager.OnLandTap(tapCoords);
        }
    }

    public void NotifyScroll(Coordinates newCoords, Coordinates oldCoords) {
        boolean handled = false;

        if (_engine.BottomRacket.Rect.Contains(oldCoords)) {
            handled = _touchManager.OnRightRaquetScroll(newCoords, oldCoords);
        }
        if (handled) return;

        if (_engine.TopRacket.Rect.Contains(oldCoords)) {
            handled = _touchManager.OnLeftRaquetScroll(newCoords, oldCoords);
        }
        if (handled) return;

        if (_engine.Land.Rect.Contains(oldCoords)) {
            handled = _touchManager.OnLandScroll(newCoords, oldCoords);
        }
    }
}
